package com.cheer.dto;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Console;
import com.cheer.exception.ServiceException;
import com.google.common.collect.Maps;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.Map;


@Data
public class MemberImportDTO {

    private static Map<String, String> headerAlias = Maps.newHashMap();

    static {
        headerAlias.put("姓名", "name");
        headerAlias.put("性别", "sex");
        headerAlias.put("出生年月", "birth");
        headerAlias.put("岗位职责", "postDescription");
        headerAlias.put("创建工作职责", "addPostDescription");
        headerAlias.put("政治面貌", "politicsStatus");
        headerAlias.put("文化程度", "cultureStatus");
        headerAlias.put("变动情况", "changeStatus");
    }

    private String name;

    private String sex;

    private Date birth;

    private Integer age;

    private String postDescription;

    private String addPostDescription;

    private String politicsStatus;

    private String cultureStatus;

    private String changeStatus;

    public static Map<String, String> getHeaderAlias() {
        return headerAlias;
    }

    public void checkAndCompute(Integer index) {
        name = StringUtils.trimToNull(name);
        if (name == null) {
            throw new ServiceException("第" + index + "条数据的姓名为空");
        }
        if (birth == null) {
            throw new ServiceException("第" + index + "条数据的出生年月为空");
        }
        int compare = DateUtil.compare(birth, new Date());
        if(compare > 0){
            throw new ServiceException("第" + index + "条数据出生日期不得大于当前时间");
        }
        addPostDescription = StringUtils.trimToNull(addPostDescription);
        if (addPostDescription == null) {
            throw new ServiceException("第" + index + "条数据的工作职责为空");
        }
        Console.log("出生日期打印："+DateUtil.format(birth,"yyyy-MM-dd"));
        age = DateUtil.ageOfNow(birth);
    }
}
